#include <iostream>

using namespace std;

template<class T>
class ArrayQueue {
public:
    ArrayQueue(int max_size) {
        this->max_size = max_size;
        this->array = new T[max_size];
        rear = front = -1;
    }
    // 添加数据
    void add_data(T data) {
        if (is_full())
            throw "queue is full";
        rear++;
        array[rear] = data;
    }
    // 取数据
    T get_data() {
        if (is_empty())
            throw "queue is empty";
        front++;
        return array[front];
    }
    // 遍历队列
    void traverse() {
        if (is_empty())
            throw "queue is empty";
        for (int i = front+1; i <= rear; i++)
            cout << array[i] << " ";
        cout << endl;
    }
    // 返回队列头
    T peek_head() {
        if (is_empty())
            throw "queue is empty";
        return array[front+1];
    }
private:
    int max_size;
    int front;
    int rear;
    T *array;
    // 判断队列是否满
    bool is_full() {
        return rear == max_size-1;
    }
    // 判断队列是否为空
    bool is_empty() {
        return rear == front;
    }
};